package com.wen.task.customTask;

import com.wen.entry.Result;
import com.wen.entry.bean.DebrisCombineEquipment;
import com.wen.entry.bean.Equipment;
import com.wen.moudle.Account;
import com.wen.moudle.Managers.BackpackManager;
import com.wen.moudle.Managers.EquipmentManager;
import com.wen.moudle.Managers.FightManager;
import com.wen.task.AbstractTask;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

// 合成蓝色碎片，卖掉垃圾属性
@Slf4j
public class EarnMoneyTask extends AbstractTask {
    private EquipmentManager equipmentManager;
    private BackpackManager backpackManager;
    private FightManager fightManager;
    public EarnMoneyTask(Account account) {
        super(account);
        equipmentManager = getEquipmentManager();
        backpackManager = getBackpackManager();
    }

    @Override
    public String getTitle() {
        return "消耗所有蓝碎片卖掉垃圾属性";
    }

    @Override
    public void run() {
        Integer id = backpackManager.getGoodId("蓝碎片");
        List<Equipment> best = new ArrayList<>();
        while (true){
            Result<DebrisCombineEquipment> combine = backpackManager.combineGood(id);
            if (combine.isSuccess()){  // 可以融合成功，一直合成
                Equipment equipment = combine.getData().getEquipment();
                log.info("融合获得 {}", equipment);
                if (account.getDefaultPropertyConfig().blueTrash(equipment)) {
                    log.info("判定是蓝色垃圾装备，卖掉 {}", equipment);
                    equipmentManager.sold(equipment);
                }else {
                    best.add(equipment);
                }

            }else {
                break;
            }
        }
        log.info("==========本次收获==========" );
        for (Equipment equipment : best) {
            log.info("{} ", equipment);
        }
    }
}
